package com.jushu.storbox.util;

import java.text.Collator;
import java.util.Comparator;

import com.jushu.storbox.entities.FileInfo;
import com.jushu.storbox.entities.FolderInfo;

public class ChinsesCharComp implements Comparator {
	private String order = "aesc";//降序 desc; 升序 ：aesc
	
	public ChinsesCharComp() {
		super();
	}
	public String getOrder() {
		return order;
	}
	public void setOrder(String order) {
		this.order = order;
	}
	
	public int compare(Object info1, Object info2) {
		Collator myCollator = Collator.getInstance(java.util.Locale.CHINA);
		String order = getOrder();
		String fileName1="";
		String fileName2="";
		if(info1 instanceof FolderInfo){
			fileName1=((FolderInfo) info1).getName();
			fileName2=((FolderInfo) info2).getName();
		}else if(info1 instanceof FileInfo){
			fileName1=((FileInfo) info1).getName();
			fileName2=((FileInfo) info2).getName();
		}
		
		
		if(null != order && "desc".equalsIgnoreCase(order)){
			if (myCollator.compare(fileName1, fileName2) > 0) {
				return 1;
			} else if (myCollator.compare(fileName1, fileName2) < 0)
				return -1;
			else
				return 0;
		}else{
			if (myCollator.compare(fileName1, fileName2) > 0) {
				return -1;
			} else if (myCollator.compare(fileName1, fileName2) < 0)
				return 1;
			else
				return 0;
		}
	}

}
